package org.darkforest.merchant.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;


public class UniqueNum {
    private static AtomicLong tmpID = new AtomicLong(0);
    private static final Object LOCKER = new Object();


    public static int getUniqueId() {
        synchronized (LOCKER) {
            long time = Long.valueOf(new SimpleDateFormat("hhmmssSSSS").format(new Date()));
            if (tmpID.get() < time) {
                tmpID.set(time);
            } else {
                tmpID.incrementAndGet();
                time = tmpID.get();
            }
            int randNum = (int) (Math.random() * 1000);
            return (int) time + randNum;
        }
    }
}